using System;
using System.Collections.Generic;
using System.Text;
using System.Management.Automation;
using System.Collections;

namespace YaTools.Yaml
{
    [Cmdlet(VerbsData.Import, "YAML")]
    public class ImportYamlCommand : YamlReaderCommand
    {

        [Parameter(Position = 0,
            Mandatory = true,
            ValueFromPipelineByPropertyName = true,
            HelpMessage = "Path to import from")]
        [ValidateNotNullOrEmpty]
        public string[] Path { get; set; }

        [Parameter]
        public SwitchParameter Document { get; set; }


        protected override void ProcessRecord()
        {
            if (Path != null)
            {
                foreach (string psPath in Path)
                {
                    ProviderInfo provider; 
                    foreach (string providerPath in 
                        GetResolvedProviderPathFromPSPath( psPath, out provider))
                    {
                        if (provider.Name == "FileSystem")
                            WriteObject( YamlLanguage.FileTo(providerPath), 
                                !Document);
                        else
                        {
                            base.WriteWarning( 
                                string.Format( "Unsupported provider: {0}", 
                                    provider.Name ));
                        }
                    }
                }
            }
        }
    }
}
